package com.cf.ongl;

import ognl.Ognl;
import ognl.OgnlContext;
import ognl.OgnlException;

/**
 * boot-awm-OnglService
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/7/11 下午 01:03
 */
public class OnglService {

    /**
     * 通过ongl获取数据
     *
     * @param data
     * @param expression
     * @return
     * @throws OgnlException
     */
    public Object getData(Object data, String expression) throws Exception {
        OgnlContext context = new OgnlContext();
        context.put("data", data);
        Object ognl = Ognl.parseExpression("#data." + (expression.replace("#", "")));
        return Ognl.getValue(ognl, context, context.getRoot());
    }
}
